const fs = require('fs')

const { loadRules } = require('../lib/load-rules')

const rulesConstants = loadRules()
const allRules = {}
const recommendedRules = {}

rulesConstants.forEach((rule) => {
  if (!rule.meta.deprecated) {
    allRules[rule.ruleId] = rule.meta.defaultSetup
  }
  if (!rule.meta.deprecated && rule.meta.recommended) {
    recommendedRules[rule.ruleId] = rule.meta.defaultSetup
  }
})

function writeRuleset(ruleset, filename) {
  const code = `/*
* WARNING: This file is autogenerated using the scripts/generate-rulesets.js
* script. Do not edit manually.
*/

module.exports = Object.freeze(${JSON.stringify({ rules: ruleset }, null, 2)})
`

  fs.writeFileSync(`./conf/rulesets/solhint-${filename}.js`, code, 'utf8')
}

writeRuleset(allRules, 'all')
writeRuleset(recommendedRules, 'recommended')
